//
//  shinyUIView.m
//  mtrGameProject
//
//  Created by darkcl on 11-2-22.
//  Copyright 2011 Memory Leaks. All rights reserved.
//

#import "shinyUIView.h"


@implementation UIView (Shiny)

- (void)applyShinyBackgroundWithColor:(UIColor *)colorA {
	
    // create a CAGradientLayer to draw the gradient on
    CAGradientLayer *layer = [CAGradientLayer layer];
	
    // get the RGB components of the color
	
    // create the colors for our gradient based on the color passed in
    layer.colors = [NSArray arrayWithObjects:(id)[colorA CGColor],
					(id)[[UIColor colorWithRed:0.41 green:0.41 blue:0.59 alpha:1.0] CGColor],
					(id)[[UIColor colorWithRed:0.41 green:0.41 blue:0.59 alpha:1.0] CGColor],
					nil];
	
    // create the color stops for our gradient
    layer.locations = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0], [NSNumber numberWithFloat:0.48], [NSNumber numberWithFloat:1.0], nil];
	
    layer.frame = self.bounds;
    [self.layer insertSublayer:layer atIndex:0];
}

- (void)applyDefaultStyle {
    // curve the corners
    self.layer.cornerRadius = 4;
	
    // apply the border
    self.layer.borderWidth = 1.0;
    self.layer.borderColor = [[UIColor lightGrayColor] CGColor];
	
    // add the drop shadow
    self.layer.shadowColor = [[UIColor blackColor] CGColor];
    self.layer.shadowOffset = CGSizeMake(2.0, 2.0);
    self.layer.shadowOpacity = 0.25;
	
	self.backgroundColor = [UIColor clearColor];
}

- (void)createTitle:(NSString *)title inPoint:(CGPoint) point{
	UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, 40)];
	titleLabel.text = title;
	titleLabel.center = point;
	titleLabel.font = [UIFont systemFontOfSize:30];
	titleLabel.textColor = [UIColor whiteColor];
	titleLabel.textAlignment = UITextAlignmentCenter;
	titleLabel.backgroundColor = [UIColor clearColor];
	
	titleLabel.layer.shadowColor = [[UIColor blackColor] CGColor];
    titleLabel.layer.shadowOffset = CGSizeMake(2.0, 2.0);
    titleLabel.layer.shadowOpacity = 0.25;
	
	[self addSubview:titleLabel];
	[titleLabel release];
	titleLabel = nil;
}

- (void)createTitle:(NSString *)title inPoint:(CGPoint) point withColor:(UIColor *)color{
	UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, 40)];
	titleLabel.text = title;
	titleLabel.center = point;
	titleLabel.font = [UIFont systemFontOfSize:30];
	titleLabel.textColor = color;
	titleLabel.textAlignment = UITextAlignmentCenter;
	titleLabel.backgroundColor = [UIColor clearColor];
	
	titleLabel.layer.shadowColor = [[UIColor blackColor] CGColor];
    titleLabel.layer.shadowOffset = CGSizeMake(2.0, 2.0);
    titleLabel.layer.shadowOpacity = 0.25;
	
	[self addSubview:titleLabel];
	[titleLabel release];
	titleLabel = nil;
}

- (void)dealloc {
    [super dealloc];
}


@end
